package com.whsxt.buss.controller;


import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.whsxt.buss.data.SalesbackData;
import com.whsxt.buss.domain.BusCustomer;
import com.whsxt.buss.domain.BusGoods;
import com.whsxt.buss.domain.BusSalesback;
import com.whsxt.buss.service.IBusCustomerService;
import com.whsxt.buss.service.IBusGoodsService;
import com.whsxt.buss.service.IBusSalesbackService;
import com.whsxt.common.PageInfo;
import com.whsxt.common.Result;
import cn.hutool.core.util.StrUtil;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 贺炯
 * @since 2019-09-28
 */
@RestController
@RequestMapping("/buss/salesback")
public class BusSalesbackController {
	
	@Autowired
	private IBusSalesbackService iBusSalesbackService;
	
	@Autowired
	private IBusGoodsService iBusGoodsService;
	
	@Autowired
	private IBusCustomerService iBusCustomerService;
	
	@RequestMapping("/list")
	public Object list(SalesbackData data) {
		IPage<BusSalesback> page = new Page<BusSalesback>(data.getPage(), data.getLimit());
		QueryWrapper<BusSalesback> queryWrapper = new QueryWrapper<BusSalesback>();
		queryWrapper.eq(data.getCustomerid()!=null&&data.getCustomerid()!= ' ', "customerid", data.getCustomerid());
		queryWrapper.eq(data.getGoodsid()!=null&&data.getGoodsid()!= ' ', "goodsid", data.getGoodsid());
		queryWrapper.gt(StrUtil.isNotBlank(data.getStartTime()), "outputtime", data.getStartTime());
		queryWrapper.lt(StrUtil.isNotBlank(data.getEndTime()), "outputtime", data.getEndTime());
		iBusSalesbackService.page(page,queryWrapper);
		List<BusSalesback> records = page.getRecords();
		for (BusSalesback busSalesback : records) {
			Integer goodsid = busSalesback.getGoodsid();
			BusGoods byId = iBusGoodsService.getById(goodsid);
			busSalesback.setGoodsname(byId.getGoodsname());
			busSalesback.setSize(byId.getSize());
			Integer customerid = busSalesback.getCustomerid();
			BusCustomer byId2 = iBusCustomerService.getById(customerid);
			busSalesback.setCustomername(byId2.getCustomername());
		}
		PageInfo pageInfo = new PageInfo(page.getTotal(), records);
		return new Result(pageInfo);
	}
}

